<?php

namespace ApplicationsModule\PeopleModule;

use \Nette\Object;

use \dibi;

use \ApplicationsModule\PeopleModule\Person;

/**
 * Base contact service class. Implements all the methods from IContactService
 * as NOT_PROVIDED and unless overriden, the service announces it does not support
 * that type of API.
 *
 * @author pavel
 */
abstract class DummyContactService extends Object implements IContactService {
    
    const NOT_PROVIDED = "not provided";
    
    //abstract static public function getServiceName();

    public function search($name) {
        return self::NOT_PROVIDED;
    }

    static function providesMail() {
        return false;
    }

    public function addMail($person_id, $mail_address) {
        return self::NOT_PROVIDED;
    }

    public function getMail($personId) {
        return self::NOT_PROVIDED;
    }

    /**
     * @param Person $person
     * @return void
     */
    public function onCreatePerson(Person $person)
    {
        $contact_info = array("id_person" => $person->getId());
        $any_info = false;
        foreach (static::providedRows() as $info_key)
        {
            $info_item = $person->getInfoField($info_key["db"]);
            if (!empty($info_item))
            {
                $any_info = true;
                $contact_info = array_merge($contact_info, array($info_key["db"] => $info_item));
            }
        }
        if ($any_info)
        {
            //todo update record for already existing contact or create new? exception for now...
            dibi::insert("contacts_" . static::getServiceName(), $contact_info)->execute();
        }
        
    }


}

?>
